<html>
<head>
	<script>
	function fbs_click(u,t) {
		<%=5%>
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=50,height=50');return false;
	}
	</script>
</head>

<% m = 1 %>
<!-- checking if selected story was not removes from database -->
<% if @story.nil? %>
 <div align="center" style="padding-down:10px;">
	<%= " the selected story was removed ! "%> </br></br>
  </div>
	   <%else%>
<!-- adding story title -->
     <div align="center">
         <h3><%= @story.title %> </h3>
      </div>

<!--checking for media url if exsist adds the image and if exsists add like and dislike button after images else adds them after content-->

  <% if !@story.media_link.nil? && @story.media_link.length > 3%>
    <div align="center">
       <img src="<%=@story.media_link%>" align="center">
    </div></br>
  
	 <% m = 2 %>
	
<!-- checking for story category if RSS allow story functionalties if not remove from view -->
<% if @story.category == "RSS" %>
  <div>
		
<!-- 3 cases for the like dislike buttons :
(1)either user didnt like or dislike before therefore display both buttons  
(2)the user liked this story before therefore remove the like button and only display the dislike button
(3)the user disliked this story before therefore remove the dislike button and display the like button only -->
		
 <!-- adding like and dislike button if user didnt like or dislike before and number of likes dislikes for this story  -->
	
 
	 <% if @action1 == [] && @action2 == [] %>
		 <%= link_to image_tag('likecopy.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1 }%>
		 <% if @likes.length > 0 %>
		  <% @a = "#{@likes.length}" %>
		 <%=link_to("#{@likes.length}"+" user".pluralize(@likes.length)+ " like this." , {:controller => "stories", :action => "liked_mobile_show", :id => (@story.id)})%>
	 <%end%><br>


<!-- checks for number of likes and dislikes per story -->
 
	 <%= link_to image_tag('dislikekh.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => -1}%>
  <% if @dislikes.length > 0 %>
	  <% @a = "#{@dislikes.length}"+" user".pluralize(@dislikes.length)+ " dislike this." %>
	  <%=link_to(@a, {:controller => "stories", :action => "disliked_mobile_show", :id => (@story.id)})%>
  <%end%>
 <%end%>
<%end%>
  
<!-- if user liked this story before remove like button and only adds dislike button -->
<!-- checks for number of likes and dislikes per story -->
  <% if @action1 != [] && @action2 == [] %>
  	<% if @likes.length > 1 %>
	  	<%= link_to image_tag('un-like.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1 }%> 
	  	 <%=link_to( "#{@likes.length}"+" user".pluralize(@likes.length)+ " like this." , {:controller => "stories", :action => "liked_mobile_show", :id => (@story.id)})%>
  <%else%>
	<%= link_to image_tag('un-like.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1 }%> 
  <%end%></br>
	
	<%= link_to image_tag('dislikekh.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => -1}%>
	  <% if @dislikes.length > 0 %>
		  <% @a = "#{@dislikes.length}"+" user".pluralize(@dislikes.length)+ " dislike this." %>
		  <%=link_to(@a , {:controller => 'stories', :action => 'disliked_mobile_show', :id => (@story.id)})%>
  	  <%end%>
 	
  <%end%>
    
  <!-- if user disliked this story before remove dislike button and only adds like button -->
  <!-- checks for number of likes and dislikes per story -->
  <% if @action2 != []  && @action1 == [] %>
	

	<%= link_to image_tag('likecopy.png' , :style =>"width:30px;height:30px;"),{ :controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1}%>
	 	<% if @likes.length > 0 %>
 			<% @a = "#{@likes.length}"+" user".pluralize(@likes.length)+ " like this." %>
 			<%=link_to(@a , {:controller => 'stories', :action => 'liked_mobile_show', :id => (@story.id)})%>
 		<%end%></br>

	<%= link_to image_tag('un-dislike.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => -1 }%> 

		<% if @dislikes.length > 1 %>
			<% @a = "#{@dislikes.length}"+" user".pluralize(@dislikes.length)+ " dislike this." %>
		  	  <%=link_to(@a , {:controller => 'stories', :action => 'disliked_mobile_show', :id => (@story.id)})%>
	  	 <%else%>
        <%end%>


    <%end%>
	
  <%end%> 
	<br>
<%end%>
     	     </div>
<!-- adds content of story  -->
 <% if !@story.mobile_content.nil?  && @story.mobile_content.length > 0 %>
	 <div class="story-comment-box-mobile well-large" style="padding-left:10px;background-color:#E0DCDC;margin-bottom:5px;">
		 <%= @story.mobile_content %><br>
	 </div>
 <%end%>
        <div>
     	 <% if m == 1 %>
	    <% if @action1 == [] && @action2 == [] %>
		 <%= link_to image_tag('likecopy.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1 }%>
		 <% if @likes.length > 0 %>
		  <% @a = "#{@likes.length}" %>
		 <%=link_to("#{@likes.length}"+" user".pluralize(@likes.length)+ " like this." , {:controller => "stories", :action => "liked_mobile_show", :id => (@story.id)})%>
		 <%end%>
	  </br>

<!-- checks for number of likes and dislikes per story -->
  
		 <%= link_to image_tag('dislikekh.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => -1}%>
		  <% if @dislikes.length > 0 %>
		  <% @a = "#{@dislikes.length}"+" user".pluralize(@dislikes.length)+ " dislike this." %>
		  <%=link_to(@a, {:controller => "stories", :action => "disliked_mobile_show", :id => (@story.id)})%>
		  <%end%>
	
		  <%end%>
		  
<!-- if user liked this story before remove like button and only adds dislike button -->
<!-- checks for number of likes and dislikes per story -->
  <% if @action1 != [] && @action2 == [] %>
  	<% if @likes.length > 1 %>
	  	<%= link_to image_tag('un-like.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1 }%> 
	  	<%=link_to( "#{@likes.length}"+" user".pluralize(@likes.length)+ " like this." , {:controller => "stories", :action => "liked_mobile_show", :id => (@story.id)})%>
  	
  	 <%else%>
		<%= link_to image_tag('un-like.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1 }%> 
  	 <%end%></br>
  	
  	 <%= link_to image_tag('dislikekh.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => -1}%>
	  <% if @dislikes.length > 0 %>
		  <% @a = "#{@dislikes.length}"+" user".pluralize(@dislikes.length)+ " dislike this." %>
		  <%=link_to(@a , {:controller => 'stories', :action => 'disliked_mobile_show', :id => (@story.id)})%>
  	<%end%>
 	
  <%end%>
    
  <!-- if user disliked this story before remove dislike button and only adds like button -->
  <!-- checks for number of likes and dislikes per story -->
  <% if @action2 != []  && @action1 == [] %>
	

	<%= link_to image_tag('likecopy.png' , :style =>"width:30px;height:30px;"),{ :controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => 1}%>
	 	<% if @likes.length > 0 %>
	 		<% @a = "#{@likes.length}"+" user".pluralize(@likes.length)+ " like this." %>
	 		<%=link_to(@a , {:controller => 'stories', :action => 'liked_mobile_show', :id => (@story.id)})%>
 		<%end%><br>

   	   <%= link_to image_tag('un-dislike.png' , :style =>"width:30px;height:30px;"), {:controller => 'likedislikes' , :action => 'thumb' , :sid => @story.id  , :act => -1 }%> 

	<% if @dislikes.length > 1 %>
		<% @a = "#{@dislikes.length}"+" user".pluralize(@dislikes.length)+ " dislike this." %>
  	  	<%=link_to(@a , {:controller => 'stories', :action => 'disliked_mobile_show', :id => (@story.id)})%>
  	 <%end%>


  <%end%>
	

 	
      <%end%>
       </div>
 
	<% if @story.category == "RSS" %>

<!-- recommend buttons  1) facebook button 2)twitter button 3)La2etlak button -->
  
<!--$$$$$$$$$$$$$$$$ Mina Adel $$$$$$$$$$$$$$$$ -->
<br>
   &nbsp;
<!-- I create the facebook sharer url with the media link, then I put it into the url part of the button -->
  <% media_url = "http://127.0.0.1:3000/stories/"+@story.id.to_s+"/get"%>
  <% facebook_url = "127.0.0.1:3000/stories/"+@story.id.to_s+"/get"%>
  <a id="Facebook" href="http://www.facebook.com/share.php?u=<%=facebook_url%>" onclick="return fbs_click(<%=facebook_url%>,via%20nokia)" target="_blank"><%= image_tag('facebook.png' , :style =>"width:32px;height:32px;padding-right:10%;")%></a>
  <!-- I create the twitter sharer url with the media link along with the message "Shared via La2etlak Nokia App", then I put it into the url part of the button -->
	<% twitter_url = "http://twitter.com/intent/tweet?url=http://127.0.0.1:3000/stories/"+@story.id.to_s+"/get&text=Shared%20via%20La2etlak%20Nokia%20App" %>
	<%= link_to image_tag('twitter.png' , :style =>"width:32px;height:32px;padding-right:10%;"), twitter_url, id: "Twitter"%>
  <!-- This is a link to the users controller, which calls the method share_story with a the story id as a parameter -->
    <%= link_to image_tag('L.png' , :style =>"width:30px;height:30px;"), {:controller => 'users' , :action => 'share_story' , :id => @story.id }, id: "La2etlak"%>
</br>
</br>
<!--$$$$$$$$$$$$$$$$ Mina Adel $$$$$$$$$$$$$$$$ -->

<!-- recommend button -->
   &nbsp;&nbsp;<%= link_to image_tag('index.jpeg' , :style =>"width:30px;height:30px;")  + "Recommend" , {:controller => 'stories' , :action => 'recommend_story_mobile_show' , :sid => @story.id }%>
<!-- flag button -->
   &nbsp;<%= link_to image_tag('flag.png' , :style =>"width:25px;height:30px;")+  "Flag" , {:controller => 'flags' , :action => 'flag' , :sid => @story.id }%></br>
   
<!-- Comments area, to comments and up or 
     any comments
     Author: Menisy-->
<br>
    <div style="padding-left:3px;float:left;">
    <h4> Comments </h4>
</div>
<br>
<div style="width:95%;">
    <% comments = Comment.find_all_by_story_id(@story.id) %>
    <% comments.each do |comment| %>

    <div class="story-comment-box-mobile well-large" style="float:left;clear:both;width:90%;margin:0.5%;">
        <h5 style="padding-top:1px;">    <%= comment.user.name || comment.user.email.split("@")[0] %> says:</h5>
        <div style="clear:both;padding:1px;">
            <div style="padding-top:0px;padding-bottom:5px;padding-left:10px;">
                <%= comment.content %>
            </div>
        </div>
        <ul class="nav">
            <% pic = nil %>
            <% if comment.downed_by_user?(current_user) then%>
                <% pic = "un-dislike.png" %>
            <% else %>
                <% pic = "dislikekh.png" %>
            <% end %>
            <li><%= link_to (image_tag (pic)) ,{:action=> :down_comment, :user_id => params[:id2], :comment_id => comment.id}, {:style =>'float:right;margin-right:4%;width:30px;height:30px;'} %>
            </li>
            <li>
                <h8 style="color:#b94a48;float:right;margin-right:1%;padding-top:2px;"> <%= comment.get_num_downs %>
                </h8>
            </li>
            <% pic2 = nil %>
            <% if comment.upped_by_user?(current_user) then%>
                <% pic2 = "un-like.png" %>
            <% else %>
                <% pic2 = "likecopy.png" %>
            <% end %>
            <li><%= link_to (image_tag (pic2)) ,{:action=> :up_comment, :user_id => params[:id2], :comment_id => comment.id}, {:style =>'float:right;margin-right:1%;width:30px;height:30px;padding-bottom:5px;'} %>
            </li>
            <li>
                <h8 style="color:#468847;float:right;margin-right:1%;"> <%= comment.get_num_ups %>
                </h8>
            </li>
        </ul>
    </div>
<% end %>
</div>
<div style="width:95%">
    <%= form_for(@comment) do |f| %>
    <div class="story-comment-box-mobile well-large" style="padding-left:3px; clear:both;width:margin:0.5%">
        <div style="margin-left:0.5%;">
            Enter a comment:
        </div>
        <%= f.text_area :content, :class => "story-textarea-mobile" %>
  
    <%= f.hidden_field :user_id, :value => @user.id %>
    <%= f.hidden_field :story_id, :value => @story.id %>

        <%= f.submit "comment" ,:class => "btn btn-large" ,:style => "margin-left:10px;" %>
        <% end %>
    
</div>

 <!-- adds related stories  -->
 <!-- if related stories are blocked added link to direct to unblocking page -->
        <% if @filtered_related_stories.length > 0%> 
        <div class="story-comment-box-mobile well" style="padding-left:10px;">
		<%= "More #{@story.interest.name} related stories: " %></br>
		<%for story in @filtered_related_stories %>
		<div style="padding-up:7px;" %>
		   <%=link_to(story.title , {:controller => 'stories', :action => 'get', :id => (story.id)})%>
		</div><br>
		   <%end%>        	
		      <%=link_to('More...', {:controller => 'users', :action => 'feed', :interest => story.interest.name})%>
        </div>
        <%else%>
          <% if @block == true %>
            <%= "All #{@story.interest.name} related stories are blocked to unblock " %><%=link_to('Click here!', {:controller => 'users', :action => 'manage_blocked_stories' })%><br>
            <%else%>
          <%= "No more #{@story.interest.name} related stories"%><br>
          <%end%>
 	<%end%>
  
<!-- block story link -->
   </br><%=link_to('Block story' , {:controller => 'users', :action => 'block_story', :id => (@story.id)})%> &nbsp;
   	
<!-- block interest link -->
   	<br><br><%=link_to('Block interest' , { :controller => 'users', :action => 'block_interest', :id => (@story.id)})%></br><br>
 
	<%end%>
	
	<%= "Added "%><%= time_ago_in_words(@story.created_at)%><%= " ago."%>
 </div>
</html> 	

